package com.wxproject.demo.Service.impl;

import com.wxproject.demo.Entity.AO.FolderCreateAO;
import com.wxproject.demo.Entity.Model.UpLoadFileDO;
import com.wxproject.demo.Entity.VO.*;
import com.wxproject.demo.Mapper.UserFileMapper;
import com.wxproject.demo.Service.UserFileService;
import com.wxproject.demo.Utils.DateUtils;
import com.wxproject.demo.Utils.FileSizeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zqf
 * @date 2021/4/11 22:19
 * @description
 */
@Service
public class UserFileServiceImpl implements UserFileService {
    @Autowired
    private UserFileMapper userFileMapper;

    @Override
    public Integer uploadFile(UpLoadFileDO userFile) {
        return userFileMapper.uploadFile(userFile);
    }

    @Override
    public List<UpLoadFileVO> getMyFileList(String userId) {
        return userFileMapper.getMyFileList(userId);
    }

    @Override
    public Integer deleteFileById(String userId,String id, String date) {
        return userFileMapper.deleteFileById(userId,id,date);
    }

    @Override
    public Integer publicFile(String id, String userId, String date) {
        return userFileMapper.publicFile(id,userId,date);
    }

    @Override
    public List<UpLoadFileVO> getPublicFile(String userId) {
        return userFileMapper.getPublicFile(userId);
    }

    @Override
    public Integer alterFilePublic(String userId,String id, Integer state, String date) {
        return userFileMapper.alterFilePublic(userId,id,state,date);
    }

    @Override
    public List<CarouselImgVO> getCarouselImg() {
        return userFileMapper.getCarouselImg();
    }

    @Override
    public Integer delCarouselImg(String id) {
        return userFileMapper.delCarouselImg(id, DateUtils.getDate());
    }

    @Override
    public List<CarouselAdminVO> getAdminCarouselImg() {
        return userFileMapper.getAdminCarouselImg();
    }

    @Override
    public Integer createFolder(FolderCreateAO folderCreateAO) {
        folderCreateAO.setCreateTime(DateUtils.getMinutesDate());
        return userFileMapper.createFolder(folderCreateAO);
    }

    @Override
    public List<FolderVO> getMyFolder(String userId) {
        return userFileMapper.getMyFolder(userId);
    }

    @Override
    public NextFileVO getNextFolder(String id) {
        List<FolderVO> folderVO = userFileMapper.getNextFolder(id);
        List<UpLoadFileVO> upLoadFileVO = userFileMapper.getNextFile(id);
        for (int i = 0; i < upLoadFileVO.size(); i++) {
            upLoadFileVO.get(i).setMemorySize(FileSizeUtil.getNetFileSizeDescription(Long.parseLong(upLoadFileVO.get(i).getMemorySize())));
        }
        NextFileVO nextFileVO = new NextFileVO();
        nextFileVO.setFileList(upLoadFileVO);
        nextFileVO.setFolderList(folderVO);
        return nextFileVO;
    }

    @Override
    public List<Object> searchFile(String name,Integer page,Integer pageSize) {
        Integer pageIndex = (page-1)*pageSize;
        List<Object> upLoadFileVO = userFileMapper.getNextFileByName(name,pageIndex,pageSize);
        return upLoadFileVO;
    }

    @Override
    public List<Object> getAllPublicFile(Integer page, Integer pageSize) {
        Integer pageIndex = (page-1)*pageSize;
        List<Object> upLoadFileVO = userFileMapper.getAllPublicFile(pageIndex,pageSize);
        return upLoadFileVO;
    }

    @Override
    public int uploadPublicFile(UpLoadFileDO userFile) {
        return userFileMapper.uploadPublicFile(userFile);
    }

}
